var uploadpic_tui={
    id_prefix_tui:"mydropzone_tui",
    myDropzone_tui:"",
    init:function(){
       if($("div#"+this.id_prefix_tui).length<1){return};
       console.info("init dropzone")
       Dropzone.autoDiscover = false;
       this.myDropzone_tui = new Dropzone("div#"+this.id_prefix_tui, { 
            url: serverUrl+"/createOrder/uploadPic",//上传地址
            paramName: "file",//文件类型
            maxFilesize: 1, // MB
            maxFiles: 1,//可上传数量
            acceptedFiles: ".jpg,.png,.gif",//上传文件类型
            dictResponseError: '文件上传失败!',//上传失败提示
            dictInvalidFileType: "你不能上传该类型文件,文件类型只能是*.jpg,*.gif,*.png。",//类型错误提示
            dictFallbackMessage:"浏览器不受支持",
            dictFileTooBig:"文件过大上传文件最大支持.",
            dictMaxFilesExceeded:"上传文件数量过多，上传失败,请删除",
            //previewsContainer:"#adds", //显示的容器
            //previewTemplate: document.querySelector('#dz-preview dz-file-preview').innerHTML,//设置显示模板
            addRemoveLinks:true,
            dictCancelUpload:"取消上传",
            dictCancelUploadConfirmation:"确认取消上传",
            dictRemoveFile:"删除",
            clickable:true,
            //createImageThumbnails: true,
            //maxThumbnailFilesize: 10,
            //thumbnailWidth: 80,
            //thumbnailHeight: 80,
            //filesizeBase: 1000,
            init:function(){
                this.on("addedfile", function(file) { 
                //上传文件时触发的事件
                    console.log("上传文件时触发的事件");
                });
                this.on("queuecomplete",function(file) {
                    //上传完成后触发的方法
                    console.log(file);
                    console.log("上传完成后触发的方法");
                });
                this.on("removedfile",function(file){
                    //删除文件时触发的方法
                    console.log("删除文件时触发的方法");
                });
                this.on("success",function(file,retdata){
                    //获取后台返回数据
                	if(retdata.data[0].indexOf("http")>-1){
                		uploadpic_tui.showpic_tui(retdata.data[0]);
                	}else{
                		uploadpic_tui.showpic_tui(imgUrl+retdata.data[0]);
                	}
                })
                this.on("dragover",function(ev){
                    //console.info(ev);
                })
            }
       });

	   	$("#mydropzone_tui_preview_div").unbind("dblclick");
	   	$("#mydropzone_tui_preview_div").bind("dblclick",function(){
	   		uploadpic_tui.clearpic_tui();
	   	});
    },
    showpic_tui:function(src){
        console.info("tui")
        _mygetBase64(src).then(function(base64){
                  console.log(base64);//处理成功打印在控制台
                  var blobdata = Util_convertBase64UrlToBlob(base64);
                  console.info(blobdata);
                  $("#"+uploadpic_tui.id_prefix_tui+"").hide();
                  $("#"+uploadpic_tui.id_prefix_tui+"_preview_div").css({
                      "background-image":  "url('"+window.URL.createObjectURL(blobdata)+"')",
                      "background-repeat": "no-repeat",
                      "background-size":   "contain"
                  });
                  $("#"+uploadpic_tui.id_prefix_tui+"_value").val(src);
                  $("#"+uploadpic_tui.id_prefix_tui+"_preview_div").show();
            },function(err){
            	  alert(err);
                  console.log(err);//打印异常信息
            });  
        
    },
    clearpic_tui:function(){
        $("#"+this.id_prefix_tui+"").show();
        $("#"+this.id_prefix_tui+"_preview_div").css({
            "background-image":  "url('')",
            "background-repeat": "no-repeat",
            "background-size":   "contain"
        });
        $("#"+this.id_prefix_tui+"_value").val("");
        $("#"+this.id_prefix_tui+"_preview_div").hide();
        $(".dz-preview").hide();
        $(".dz-preview:not(':last')").remove();
        if(uploadpic_tui.myDropzone_tui!=""){
        	uploadpic_tui.myDropzone_tui.removeAllFiles();
        }
        $(".dz-message").show();
    }
}
uploadpic_tui.init();